<template>
  <!-- 广播管理 -->
  <div style="padding: 20px">
    <el-form inline :model="form" ref="form" label-width="100px" size="mini">
      <el-form-item label="广播地点" prop="broadcastAddress">
        <el-input
          placeholder="请输入广播地点"
          v-model="form.broadcastAddress"
        ></el-input>
      </el-form-item>
      <el-button
        type="primary"
        size="mini"
        icon="el-icon-search"
        @click="handleQuery"
        >搜索</el-button
      >
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
        >新增</el-button
      >
      <el-button size="mini" icon="el-icon-refresh" @click="resetForm('form')"
        >重置</el-button
      >
    </el-form>
    <el-table :header-cell-style="thaderBack" :data="tableData">
      <el-table-column label="序号" width="80" align="center">
        <template slot-scope="scope">
          <span style="margin-left: 10px">{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="broadcastName"
        label="广播名称"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="broadcastAddress"
        label="广播地点"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column prop="areacode" label="广播编号" show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        prop="broadcastStatus"
        label="状态"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          {{ scope.row.broadcastStatus == 0 ? '正常' : '停用' }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="left"
        class-name="small-padding fixed-width"
        width="130"
      >
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="handleUpdate(scope.row)"
            ><i class="el-icon-edit"></i>编辑</el-button
          >
          <el-button type="text" size="mini" @click="handleDelete(scope.row)"
            ><i class="el-icon-delete"></i>删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="config.page"
      :page-size="config.limit"
      layout="total,prev, pager, next, jumper"
      :total="total"
      class="pager"
    ></el-pagination>
    <el-dialog
      width="30%"
      :title="statusType === 'add' ? '新增' : '编辑'"
      :visible.sync="isShow"
    >
      <el-form ref="FormDetails" :model="FormDetails" label-width="80px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="广播名称" prop="broadcastName">
              <el-input
                v-model.trim="FormDetails.broadcastName"
                placeholder="请输入广播名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="广播地点" prop="broadcastAddress">
              <el-input
                v-model.trim="FormDetails.broadcastAddress"
                placeholder="请输入广播地点"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="广播编号" prop="areacode">
              <el-input
                v-model.trim="FormDetails.areacode"
                placeholder="请输入广播编号"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="状态" prop="broadcastStatus">
              <el-select
                v-model="FormDetails.broadcastStatus"
                placeholder="请选择状态"
                style="width: 100%"
              >
                <el-option label="正常" :value="0"></el-option>
                <el-option label="停用" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="submitSend">确 定</el-button>
        <el-button @click="closeDetails" type="button">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { communal } from '@/api/common.js'
export default {
  mixins: [communal],
  data() {
    return {
      url: '/xbtBroadcast/list',
      addUrl: '/xbtBroadcast/add',
      editUrl: '/xbtBroadcast/edit',
      form: {
        broadcastAddress: null
      },
      tableData: [],
      FormDetails: {
        FormDetails: null,
        broadcastAddress: null
      },
      statusType: 'add'
    }
  },
  methods: {
    handleUpdate(row) {
      this.resetFormDetails('FormDetails')
      this.$http
        .get('/xbtBroadcast/detail?broadcastId=' + row.broadcastId)
        .then(res => {
          if (res.code === 200) {
            this.FormDetails = res.data
            this.statusType = 'edit'
            this.isShow = true
          }
        })
    },
    handleDelete(row) {
      this.$confirm('是否确认删除?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$http
            .post('/xbtBroadcast/del?ids=' + row.broadcastId)
            .then(response => {
              if (response.code === 200) {
                this.$message({
                  type: 'success',
                  message: '删除成功！'
                })
                this.config.page = 1
                this.getList()
              }
            })
        })
        .catch(function() {})
    }
  }
}
</script>

<style lang="scss" scoped></style>
